#ifndef COMMON_MACRO_SERIALIZE_H
#define COMMON_MACRO_SERIALIZE_H 1

/* TODO: useless */

/*
 * Take good care when using these macros. They assume
 * the output is large enough to hold the data.
 */
#define SERIALIZE_ITEM_SIZED(destination, source, offset, size) { \
	memcpy(&(destination)[offset], source, size); \
	offset += size; \
}
#define SERIALIZE_ITEM(destination, source, offset) SERIALIZE_ITEM_SIZED(destination, source, offset, sizeof(*(source)))
#define SERIALIZE_STRING(destination, sourcestr, offset, maxlen) { \
	if (maxlen > 0) { \
		destination[maxlen] = '\0'; \
		SERIALIZE_ITEM_SIZED(destinatino, sourcestr, offset, util_strnlen(sourcestr, maxlen)); \
	} \
}


#define DESERIALIZE_ITEM_SIZED(destination, source, offset, size) { \
	memcpy(destination, &(source)[offset], size); \
	offset += size; \
}
#define DESERIALIZE_ITEM(destination, source, offset) DESERIALIZE_ITEM_SIZED(destination, source, offset, sizeof(*(source)))
#define DESERIALIZE_STRING(destinationstr, source, offset, maxlen) { \
	destinationstr = util_strndup(source, maxlen); \
	offset += strlen(destinationstr) + 1; \
}

#endif

